package com.mmy.dao.ship;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.ship.TShipPort;

public interface TShipPortRepository extends JpaRepository<TShipPort, Integer> {

	/*
	 * 获取最大值id
	 */
	@Query(value = "select MAX(iPortID) from tShipPort", nativeQuery = true)
	Object getMaxPortID();

	/*
	 * 新增id
	 */

	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tShipPort(iPortID, cPortName, iZoneID, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (:portID, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(@Param("portID") int portID);

	/*
	 * 根据id删除
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tShipPort where tShipPort.iPortID in (:lstPortID)", nativeQuery = true)
	void delShipPort(@Param("lstPortID") List<Integer> lstPortID);

	/*
	 * 根据id查找
	 */
	@Query(value = "select *  from tShipPort where iPortID = :iPortID", nativeQuery = true)
	TShipPort findByPortID(@Param("iPortID") int iPortID);

}
